package com.fitness.front.service.impl.common;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.IdUtil;
import org.springframework.stereotype.Service;

import java.io.File;
import java.io.InputStream;
import java.util.Date;

@Service
public class UploadFileServiceImpl {

    //项目工作目录下新建一个files目录存文件
    public static final String DEFAULT_UPLOAD_FOLDER = FileUtil.getParent(System.getProperty("user.dir"),1)
            + FileUtil.FILE_SEPARATOR + "files" + FileUtil.FILE_SEPARATOR + "front" + FileUtil.FILE_SEPARATOR;

    public UploadFileServiceImpl() {
        if(!FileUtil.exist(DEFAULT_UPLOAD_FOLDER)){
            FileUtil.mkdir(DEFAULT_UPLOAD_FOLDER);
        }
    }

    public String uploadFile(InputStream inputStream, String fileName) {
        File file = FileUtil.writeFromStream(inputStream,DEFAULT_UPLOAD_FOLDER + IdUtil.simpleUUID());
        return file.getAbsolutePath();
    }

    private String mkDirByDay(){
        Date now = new Date();
        int year = DateUtil.year(now);
        //月份从0开始
        int month = DateUtil.month(now) + 1;
        int day = DateUtil.dayOfMonth(now);

        return null;
    }

    public static void main(String[] args) {
        System.out.println(DateUtil.thisMonth());
    }
}
